package com.qdxwx.manage.controller.my;

import com.qdxwx.common.page.PageRequest;
import com.qdxwx.common.page.TableDataInfo;
import com.qdxwx.common.utils.TKString;
import com.qdxwx.data.service.order.OrderDetailService;
import com.qdxwx.manage.controller.BaseController;

import com.qdxwx.manage.support.SessionUtils;
import com.qdxwx.models.enums.OrderType;
import com.qdxwx.models.manager.Manager;
import com.qdxwx.models.order.OrderDetail;
import com.qdxwx.models.order.OrderDetailQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import jakarta.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 订单流水Controller
 * Qdx NetSchool Platform
 * @author qdxwx
 * @updateTime 2022/5/25
 * @description
 */
@Controller
@RequestMapping("/my/order/detail")
public class MyOrderDetailController extends BaseController {

    @Autowired
    private OrderDetailService orderDetailService;

    @GetMapping("/list.html")
    public String list() {
        return "my/my-order-detail-list";
    }

    /**
     * 查询订单流水列表
     */
    @PostMapping("/list.json")
    @ResponseBody
    public TableDataInfo list(HttpServletRequest request) {
        Manager manager = SessionUtils.getManager();
        if(manager == null) return TableDataInfo.error("登录超时");
        OrderDetailQuery query = new OrderDetailQuery();
        query.setCourseName(TKString.queryKey(request.getParameter("courseName")));
        query.setAuthStatus(TKString.queryKey(request.getParameter("authStatus")));
        query.setOrderNo(TKString.queryKey(request.getParameter("orderNo")));
        query.setOrderType(OrderType.COURSE.toString());
        query.setUserId(manager.getUserId());
        List<OrderDetail> list = orderDetailService.getListByCourse(query, PageRequest.form(request));
        TableDataInfo rspData = new TableDataInfo();
        rspData.setCode(0);
        rspData.setRows(list);
        rspData.setTotal(orderDetailService.countByCourse(query));
        return rspData;
    }
}
